<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="Resources/dynamsoft.webtwain.initiate.js"> </script>
    <script type="text/javascript" src="Resources/dynamsoft.webtwain.config.js"> </script>
</head>
<body>
<div id="myBtn">myBtn</div>
<!--id为‘dwtcontrolContainer’的div是扫描的容器.id和尺寸定义在dynamsoft.webtwain.config.js文件中.可以修改-->
<div id="dwtcontrolContainer"></div>


<script type="text/javascript">
//    Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady);
 /*   Dynamsoft.WebTwainEnv.RegisterEvent('OnWebTwainReady', function() {
        DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
    });*/
    var DWObject;// Dynamic Web TWAIN 对象
    /* OnWebTwainReady event fires as soon as Dynamic Web TWAIN is initialized and ready to be
     used. It is the best place to add event listeners */
/*    function Dynamsoft_OnReady(){
        debugger
        DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');   //初始化
        DWObject.RegisterEvent("OnPostTransfer", Dynamsoft_OnPostTransfer);
        /!*   DWObject.RegisterEvent("OnPostTransfer", function() {
           your code goes here
        });*!/
       /!* DWObject.RegisterEvent("OnPostTransfer", function(index) {
            CurrentImage.value = index + 1;
        });*!/
    }*/
    var btn = document.getElementById("myBtn");
    btn.onclick = function(event){
        debugger
        DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');   //初始化
    };
    function AcquireImage(){
        if(DWObject) {
            DWObject.Resolution = 200; //属性 扫描200 DPI
            DWObject.Rotate(0, 45, false); //方法 rotate the 1st image in the buffer by 45 degrees
            //事件
            // OnMouseClick     mouse clicking
            // OnPostTransfer   event for the end of transferring one image,

            DWObject.IfDisableSourceAfterAcquire = true;
            DWObject.SelectSource();
            DWObject.OpenSource();           // You should customize the settings after opening a source
            DWObject.IfShowUI = false;     // Hide the User Interface of the scanner
            DWObject.IfFeederEnabled = true;    // Use the document feeder to scan in batches
            DWObject.IfDuplexEnabled = false;   // Scan in Simplex mode (only 1 side of the page)
            DWObject.PixelType = EnumDWT_PixelType.TWPT_GRAY; // Scan pages in GRAY
            DWObject.Resolution = 200;     // Scan pages in 200 DPI
            //BitDepth  Brightness  Contrast  PageSize
            //PixelFlavor  XferCount  IfAutoDiscardBlankpages
            //IfAutomaticDeskew  IfAutomaticBorderDetection
            DWObject.CurrentImageIndexInBuffer = 2; // Show the 3rd image in the buffer
            /* Show images in buffer with 2 * 2 view */
            DWObject.SetViewMode(2, 2);
            DWObject.AcquireImage();     // Start scanning
        }
    }
    function Dynamsoft_OnPostTransfer() {
        /* This event OnPostTransfer will be triggered after a transfer ends. */
        /* your code goes here*/
    }
    function DynamicWebTwain_OnMouseClick(index) {
        CurrentImage.value = index + 1;
    }
</script>
</body>
</html>